package com.rgs.platform.service.impl;

import com.github.pagehelper.PageInfo;
import com.rgs.base.core.page.IPageRequestModel;
import com.rgs.base.database.DataPageUtil;
import com.rgs.base.database.SqlPlusUtil;
import com.rgs.platform.entity.CrawlingCovidDO;
import com.rgs.platform.filter.CovidInfoFilterDTO;
import com.rgs.platform.mapper.CrawlingCovidMapper;
import com.rgs.platform.service.CrawlingCovidService;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

/**
 * @program: com-rgs-parent
 * @description:
 * @author: Mr.Ren
 * @create: 2022-11-02 20:46
 **/
@Service
public class CrawlingCovidServiceImpl implements CrawlingCovidService {

    @Resource
    private CrawlingCovidMapper crawlingCovidMapper;

    @Override
    public int batchInsertCovidData(List<CrawlingCovidDO> covidList) {
        return crawlingCovidMapper.insertBatchList(covidList);
    }

    @Override
    public Optional<CrawlingCovidDO> selectByFilter(CovidInfoFilterDTO billInfoFilter) {
        Example example = SqlPlusUtil.sqlFilterJoin(CrawlingCovidDO.class, billInfoFilter);
        return crawlingCovidMapper.selectByExample(example).stream().findFirst();
    }

    @Override
    public List<CrawlingCovidDO> listByFilter(CovidInfoFilterDTO billInfoFilter) {
        Example example = SqlPlusUtil.sqlFilterJoin(CrawlingCovidDO.class, billInfoFilter);
        return crawlingCovidMapper.selectByExample(example);
    }

    @Override
    public PageInfo<CrawlingCovidDO> listPageByFilter(IPageRequestModel iPageRequestModel, CovidInfoFilterDTO billInfoFilter) {
        Example example = SqlPlusUtil.sqlFilterJoin(CrawlingCovidDO.class, billInfoFilter);
        return DataPageUtil.selectPageList(iPageRequestModel, () -> crawlingCovidMapper.selectByExample(example));
    }

    @Override
    public CrawlingCovidDO selectById(String id) {
        return crawlingCovidMapper.selectByPrimaryKey(id);
    }
}
